package com.example.android.debuggermenu;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

public class SoundPoolThread extends Thread {
	private static final String TAG = GameThread.class.getSimpleName();
	private boolean running;
	private SoundPool snd;
    private int bsnd=0;
    private int ssnd=0;
    private int wsnd=0;	
    private boolean playSuccess=false;
    private boolean playWrong=false;
    private boolean playBackground=true;
    private Handler mHandler;
    
    public SoundPoolThread() {
    	super();
    	//Accessing the audio files stored on the SD card
        snd=new SoundPool(5000,AudioManager.STREAM_SYSTEM,0);
        bsnd=snd.load("/mnt/sdcard/bgm4.ogg", 0);
        ssnd=snd.load("/mnt/sdcard/successogg.ogg", 0);
        wsnd=snd.load("/mnt/sdcard/wrongogg.ogg", 0);
    }
    
    public void setRunning(boolean running) {
        this.running = running;
    }
    
    public void setPlaySuccess() {
        this.playSuccess = true;
    }
    
    public void setPlayWrong() {
        this.playWrong = true;
    }
    
    public void run(){
    	    		
		    	while(running) {
		    		//if(playBackground) {
		    			//snd.play(bsnd, 1, 1, 0, -1, 1);
		    			//playBackground=false;
		    		//}
		    		if(playSuccess) {
		    			snd.play(ssnd, 1, 1, 0, 0, 1);
		    			playSuccess=false;
		    		}
		    		if(playWrong) {
		    			snd.play(wsnd, 1, 1, 0, 0, 1);
		    			playWrong=false;
		    		}
		    	}
		    	//snd.stop(bsnd);
		    	//snd.stop(wsnd);
		    	//snd.stop(ssnd);
		    	snd.release();
    		
    }
}
